globalThis.Z_FORM_TPL = `<div class="http-com comformscr2">
  <template v-if="config.debug">{% verbatim %}{{ {% endverbatim %} parts {% verbatim %} }} {% endverbatim %}</template>
  {% for part in CONFIG.parts %}
  {% set partConfigKey = 'config.parts[' ~ loop.index0 ~ '].def' %}
  {% set pathKey = "parts." ~ part.name %}
  {% set pathSKey = "'parts." ~ part.name ~ "'" %}
  {% set modelKey = pathKey ~ ".model"  %}
    {% if part.type == 'form' %}
    <el-form class="z-form http-com-part http-com-part__{{ part.name }} {{ part.name }}"
             ref="comformscr2__{{ part.name }}" :model="{{ pathKey }}.model"
             :rules="formRules"
              {{ partStr[part.name].attr }}
             {% for KeyValue in part.def.ui.attrs %} {{ KeyValue[0] }}="{{ KeyValue[1] }}"{% endfor %}
    >
      {{ partStr[part.name]._tpl }}
      <slot-com :defs="slotContent" :attrs="{parts}"
                :binds="{name: '{{ part.name }}', ctx: exportCtx,  partName: '{{ part.name }}', parts, process: '{{ CONFIG.process}}' }"
                name="form_afterend"></slot-com>
    </el-form>
    {% endif %}
  {% endfor %}
</div>`


globalThis.Z_FORM_TPL2 = function (data) {
  // console.log('data', data)
  let CONFIG = data.CONFIG;
  let parts = data.CONFIG.parts;
  let partStr = data.partStr;
  let content = ''

  parts.forEach((part, partIndex) => {
    // let partConfigKey = 'config.parts[' +  partIndex + '].def'
    let pathKey = "parts." + part.name
    // let pathSKey = "'parts." + part.name + "'"
    // let modelKey = pathKey + ".model"
    let partDataSet = partStr[part.name]

    let attrStr = ''
    ZY.lodash.each(part.def.ui.attrs, function (item) {
      attrStr = attrStr + ` ${item[0]}="${item[1]}"`
    })


    content = content + `
       <el-form class="z-form http-com-part http-com-part__${part.name} ${part.name}"
             ref="comformscr2__${part.name}" :model="${ pathKey }.model"
             :rules="formRules"     
             ${ partDataSet.attr }    ${attrStr}  
    >
      ${partDataSet._tpl}
      <slot-com :defs="slotContent" :attrs="{parts}"
                :binds="{name: '${part.name}', ctx: exportCtx,  partName: '${part.name}', parts, process: '${ CONFIG.process ?? ''}' }"
                name="form_afterend"></slot-com>
    </el-form>
    
    `
  })

  return `<div class="http-com comformscr2">${content}</div>`
}


import * as _main from './main'
export {buildVueComponentMan} from "./main";
import {createZformCommon} from "./zform";

export function initZForm(...args) {
  globalThis.createZformCommon = createZformCommon;
  return _main.initZForm(...args)
}
